package com.inspur.demo.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * @ClassName LoginFilter
 * @Description TODO
 * @Company inspur
 * @Author Mark.Zhang
 * @Date 2019/5/17 15:55
 * @Version 1.0 
 */
@Slf4j
@Component
@WebFilter(urlPatterns = "/login/*", filterName = "myLoginFilter")
public class LoginFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        String name = servletRequest.getParameter("name");
        log.info("doFilter:{}", name);
        if ("admin".equals(name)) {
            log.info("登录成功");
            filterChain.doFilter(servletRequest, servletResponse);
        } else {
            filterChain.doFilter(servletRequest, servletResponse);
        }
    }

    @Override
    public void destroy() {

    }
}
